# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=privoxy
pkgver=3.0.34
pkgrel=3
pkgdesc="web proxy with advanced filtering capabilities"
url="https://www.privoxy.org/"
arch="all"
license="GPL-2.0-or-later"
pkgusers="privoxy"
pkggroups="privoxy"
makedepends="autoconf automake pcre-dev zlib-dev coreutils"
install="privoxy.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://downloads.sourceforge.net/ijbswa/privoxy-$pkgver-stable-src.tar.gz
	$pkgname.initd
	$pkgname.logrotate
	privoxy-alpine.patch
	"
options="!check" # No test suite
builddir="$srcdir/$pkgname-$pkgver-stable"

# secfixes:
#   3.0.33-r0:
#     - CVE-2021-44540
#     - CVE-2021-44541
#     - CVE-2021-44542
#     - CVE-2021-44543
#   3.0.32-r0:
#     - CVE-2021-20272
#     - CVE-2021-20273
#     - CVE-2021-20274
#     - CVE-2021-20275
#     - CVE-2021-20276
#   3.0.31-r0:
#     - CVE-2021-20216
#     - CVE-2021-20217
#   3.0.29-r0:
#     - CVE-2021-20210
#     - CVE-2021-20211
#     - CVE-2021-20212
#     - CVE-2021-20213
#     - CVE-2021-20214
#     - CVE-2021-20215

prepare() {
	default_prepare

	autoreconf -fvi
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--localstatedir=/var/ \
		--enable-zlib \
		--enable-dynamic-pcre \
		--with-user=privoxy \
		--with-group=privoxy \
		--sysconfdir=/etc/privoxy \
		--docdir=/usr/share/doc/$pkgname
	make
}

package() {
	make DESTDIR="$pkgdir" install

	rm -f "$pkgdir"/var/log/privoxy/*

	install -D -m755 "$srcdir"/privoxy.initd "$pkgdir"/etc/init.d/privoxy
	install -D -m644 "$srcdir"/privoxy.logrotate \
		"$pkgdir"/etc/logrotate.d/privoxy

	find "$pkgdir"/etc/privoxy/ -type d -exec chmod 770 {} \;
	find "$pkgdir"/etc/privoxy/ -type f -exec chmod 660 {} \;

	chown -R privoxy:privoxy "$pkgdir"/var/log/privoxy \
		"$pkgdir"/etc/privoxy

	rmdir "$pkgdir"/var/run
}

sha512sums="
f963419ae2cb6dd72cd892fa043768d99a4118792833de2e666d6a800fbe9a7fcb0641f15e3211e0b01a74609c65aeb60af1051f1a19daa1048314599679b685  privoxy-3.0.34-stable-src.tar.gz
346bda3a2108547569af3397c77e092c54fa0c20bc6d3bb1d4c202b4e2b8d9c13018eab0a326cd9632310ec8052600ee7db4b6011610faec386c399cdd01af9c  privoxy.initd
18fc06c7f0c0dff5e1ace89c5557fc52bb207e183ca2227361512894895888134156fbb0b80ab14cbe8b1458cbe214739b2d797b249a4e658c2410d62021d642  privoxy.logrotate
1059feed20a31d7d2b5d1f44b7b1af40373d87dbd9e7e83c8998ac1b4e27dfbfdfeb6a9ea7934e15d0c14fed1fd03fb63d2ec8d2a6b53e5884a21dc8df4828fc  privoxy-alpine.patch
"
